|
|
|
| |
|
|
|
|
When you are performing file operations that take a long time (more than a few seconds), display an AVI file like Windows does. This capability is discussed in the section "Adding Video with the Animation Control" in Chapter 12, "Microsoft Common Controls." |
|
|
|
|
|
|
|
|
|
|
Visual Basic also allows you to delete files by using the Kill statement. Kill can use wildcards to specify multiple files, as in the following example: |
|
|
|
|
|
|
|
|
The Name statement is like MS-DOS's RENAME command but can be used on only one file at a time: |
|
|
|
|
|
|
|
|
You also can use Name like the MOVE command in MS-DOS if the specified paths are different: |
|
|
|
|
|
|
|
|
'Moves the file to a new directory
MkDir "D:\NewDir"
Name "C:\Windows\Desktop\TEST1.TXT" AS "D:\NewDir\TEST2.TXT" |
|
|
|
|
|
|
|
|
In the preceding example, note the MkDir statement, which you probably have guessed is used to create a new directory. The MkDir and RmDir statements add and remove directories, just like their MD and RD counterparts in MS-DOS. |
|
|
|
|
|
|
|
|
Setting the Current Directory |
|
|
|
|
|
|
|
|
In the examples discussed so far, the path has always included the drive and directory. However, as you may recall from using MS-DOS, during the context of your MS-DOS session, you are always "in" a certain directory, which is usually displayed to the left of the MS-DOS cursor. For example, if you type CD \WINDOWS, you can rename, copy, or delete files within the WINDOWS directory without specifying C:\WINDOWS in the pathname. The same concept of a current directory applies to Visual Basic. By using the ChDir and ChDrive statements, you can set the current working directory on each drive and switch between current drives, eliminating the need to specify the full path for each file operation: |
|
|
|
|
|
|
|
|
'Change to the desired directory and drive and rename a file
chdir "C:\Windows\Desktop"
chdrive "C:"
Name "TEST1.TXT" As "TEST2.TXT"
'Delete a file in the current directory
ChDrive "D:"
ChDir "D:\DATA"
Kill "OLDDATA.DAT" |
|
|
|
|
|
|
|
|
Performing deletes can be dangerous if you don't know the current directory. Fortunately, Visual Basic offers a function that provides this value: the CurDir$ function. The syntax of CurDir$ is |
|
|
|
|
|
|
|
|
stringvar = CurDir$([Drive]) |
|
|
|
|
|
|
|
|
|
You can use the Left$ function to get the current drive, as in the following example: |
|
|
|
|
|
|
|
|
sDriveLetter = Left$(CurDir$(),1)  |
|
|
|
|
|
|
|